package cn.jbit.bdqn.action.cus;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

import cn.jbit.bdqn.biz.cus.Inface.IDespatchBiz;
import cn.jbit.bdqn.biz.cus.Inface.IMarketChangeBiz;
import cn.jbit.bdqn.biz.login.Inface.IUserBiz;

import cn.jbit.bdqn.entity.Dictionary;
import cn.jbit.bdqn.entity.cus.MarketChange;

import cn.jbit.bdqn.entity.login.Role;
import cn.jbit.bdqn.entity.login.User;
import cn.jbit.bdqn.util.Condition;
import cn.jbit.bdqn.util.PageBean;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class MarketChangeAction extends ActionSupport {

	private IMarketChangeBiz markBiz;
	private Condition cond;
	
	public Condition getCond() {
		return cond;
	}
	public void setCond(Condition cond) {
		this.cond = cond;
	}
	
	public void setMarkBiz(IMarketChangeBiz markBiz) {
		this.markBiz = markBiz;
	}
	
	public IMarketChangeBiz getMarkBiz() {
		return markBiz;
	}

	private PageBean pag=new  PageBean();
	
	public PageBean getPag() {
		return pag;
	}



	public void setPag(PageBean pag) {
		this.pag = pag;
	}


	@SuppressWarnings("unchecked")
	public String findAllMarket() throws Exception{
		ActionContext actionContext=ActionContext.getContext();
		Map session= actionContext.getSession();
		List<MarketChange> marklist=new ArrayList<MarketChange>();
		marklist=markBiz.selectMarketByValues(cond,pag);
		session.put("marklist",marklist);
		return SUCCESS;
			
	}
	
	
	@SuppressWarnings("unchecked")
	public String selectMarket() throws Exception{
		
	/*	ActionContext actionContext=ActionContext.getContext();
		Map session= actionContext.getSession();*/

		List<MarketChange> marklist=markBiz.selectMarketByValues(cond,pag);
			//session.put("marklist",marklist);
			return SUCCESS;
		
	}
	
	private MarketChange market;
	private String peram;
	
	public String getPeram() {
		return peram;
	}
	public void setPeram(String peram) {
		this.peram = peram;
	}
	public MarketChange getMarket() {
		return market;
	}
	public void setMarket(MarketChange market) {
		this.market = market;
	}
	public String saveUpDelMarket() throws Exception{
		System.out.println(peram+" <>"+market.getCusName());	
		market.setStatue(new Dictionary(34));
		if(peram!=null&&market!=null){
			if(peram.equals("update")){
				if(markBiz.updateMarket(market)){
					return SUCCESS;
				}
				return INPUT;
				}else if(peram.equals("save")){
					
					if(markBiz.saveMarket(market)){
						return SUCCESS;
					}
					return INPUT;
				}else if(peram.equals("delete")){
					if(markBiz.deleteMarket(market)){
						return SUCCESS;
					}
					return INPUT;
				}
		}
		
		return INPUT;
	}
	private IUserBiz userBiz;

	
	public IUserBiz getUserBiz() {
		return userBiz;
	}
	public void setUserBiz(IUserBiz userBiz) {
		this.userBiz = userBiz;
	}
	@SuppressWarnings("unchecked")
	public String zhiPai() throws Exception{
		ActionContext actionContext=ActionContext.getContext();
		Map session= actionContext.getSession();
		Role role=new Role(2);
		List<User> userList= userBiz.userList(role);
		if(userList.size()>0){
			session.put("userList", userList);
			return SUCCESS;
		}
		return INPUT;
	}
	private IDespatchBiz despBiz;
	private User user;
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public IDespatchBiz getDespBiz() {
		return despBiz;
	}
	public void setDespBiz(IDespatchBiz despBiz) {
		this.despBiz = despBiz;
	}
	private Date desdate;
	
	public Date getDesdate() {
		return desdate;
	}
	public void setDesdate(Date desdate){
		this.desdate = desdate;
	}
	public String saveDespatch() throws Exception{
		market.setStatue(new Dictionary(28));
	
		if(despBiz.saveDespatch(user, market,desdate)){
			if(markBiz.updateMarket(market)){
			return SUCCESS;
			}
		}
		return INPUT ;
	}
	
}
